package com.sumapay.fsb.common.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateUtil {

    @Value("${rest.http.connectTimeout}")
    private int connectTimeout;

    @Value("${rest.http.readTimeout}")
    private int readTimeout;

    @Bean
    public RestTemplate getRestTemplate(ClientHttpRequestFactory requestFactory) {
        RestTemplate restTemplate = new RestTemplate(requestFactory);
        return restTemplate;
    }


    @Bean
    public ClientHttpRequestFactory clientHttpRequestFactory() {
        SimpleClientHttpRequestFactory ClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
        ClientHttpRequestFactory.setConnectTimeout(connectTimeout);
        ClientHttpRequestFactory.setReadTimeout(readTimeout);
        return ClientHttpRequestFactory;
    }

}
